//
//  YTFishpondTKTableViewCell.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/7/30.
//

#import "YTFishpondTKTableViewCell.h"

@interface YTFishpondTKTableViewCell ()
@property (nonatomic ,strong) UILabel * alarmLab;
@property (nonatomic ,strong) UIImageView* tkImg;
@property (nonatomic ,strong) UILabel * nameLab;

@end

@implementation YTFishpondTKTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self setupView];
    }
    return self;
}


- (void)setupView{
    
    self.backgroundColor = UIColor.clearColor;
    self.contentView.backgroundColor = UIColor.clearColor;
    self.contentView.clipsToBounds = YES;
    self.userInteractionEnabled = YES;
    self.contentView.userInteractionEnabled = YES;
    self.clipsToBounds = YES;

    UIView * makeview = [UIView new];
    makeview.clipsToBounds = YES;
    makeview.backgroundColor = KcolorHex(@"#F2F7FF");
    [self.contentView addSubview:makeview];
    [makeview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(10));
        make.right.offset(kwt(-10));
        make.top.bottom.offset(0);
    }];
    
    UIView * backview = [UIView new];
    backview.backgroundColor = UIColor.whiteColor;
    [DTKTool YJ:kwt(7) andView:backview];
    [makeview addSubview:backview];
    [backview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(10));
        make.right.offset(kwt(-10));
        make.top.offset(0);
        make.bottom.offset(kwt(-10));
    }];
    
    UILabel * alarmLab = [DTKTool labelWithText:@"正常" andFont:kCFont(13) andTextColor:KcolorHex(@"#0967FF")];
    alarmLab.backgroundColor = KcolorHex(@"#E0ECFF");
    self.alarmLab = alarmLab;
    [DTKTool YJ:kwt(5) andView:alarmLab];
    [backview addSubview:alarmLab];
    alarmLab.textAlignment = NSTextAlignmentCenter;
    [alarmLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(2));
        make.width.offset(kwt(40));
        make.top.offset(kwt(2));
        make.height.offset(kwt(20));
    }];
    
    UIImageView * tkImg = kimageView(@"single");
    self.tkImg = tkImg;
    MJWeakSelf
    tkImg.addClickBlock(^{
        [weakSelf openTkClick];
    });
    [backview addSubview:tkImg];
    [tkImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(10));
        make.width.offset(kwt(76));
        make.centerY.offset(0);
        make.height.offset(kwt(76));
    }];
    
    UILabel * nameLab = [DTKTool labelWithText:@"--" andFont:kCFont(18) andTextColor:KcolorHex(@"#121212")];
    self.nameLab = nameLab;
    [backview addSubview:nameLab];
    [nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(100));
        make.top.offset(kwt(14));
    }];
    
    UIView * dbview = [UIView new];
    dbview.backgroundColor = KcolorHex(@"#F3F6FA");
    [DTKTool YJ:kwt(3) andView:dbview];
    [backview addSubview:dbview];
    [dbview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(100));
        make.top.offset(kwt(42));
        make.width.offset(kwt(60));
        make.height.offset(kwt(56));
    }];
    dbview.addClickBlock(^{
        if(weakSelf.openDBBlock){
            weakSelf.openDBBlock(weakSelf.model);
        }
    });
    UIImageView * dbImg = kimageView(@"daiban 1");
    [dbview addSubview:dbImg];
    [dbImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(kwt(8));
        make.height.width.offset(kwt(20));
    }];
    
    
    UILabel * dbtemplab = [DTKTool labelWithText:@"待办" andFont:kFont(13) andTextColor:KcolorHex(@"#7D7D7D")];
    [dbview addSubview:dbtemplab];
    [dbtemplab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(kwt(36));
     
    }];
    
    
    UIView * rwview = [UIView new];
    rwview.backgroundColor = KcolorHex(@"#F3F6FA");
    [DTKTool YJ:kwt(3) andView:rwview];
    [backview addSubview:rwview];
    [rwview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(dbview.mas_right).offset(kwt(18));
        make.top.equalTo(dbview);
        make.width.offset(kwt(60));
        make.height.offset(kwt(56));
    }];
    rwview.addClickBlock(^{
        if(weakSelf.openJRRWBlock){
            weakSelf.openJRRWBlock(weakSelf.model);
        }
    });
    UIImageView * rwImg = kimageView(@"renwu");
    [rwview addSubview:rwImg];
    [rwImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(kwt(8));
        make.height.width.offset(kwt(20));
    }];
    
    
    UILabel * rwtemplab = [DTKTool labelWithText:@"今日任务" andFont:kFont(13) andTextColor:KcolorHex(@"#7D7D7D")];
    [rwview addSubview:rwtemplab];
    [rwtemplab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(kwt(36));
    }];
        
    UIView * rzview = [UIView new];
    rzview.backgroundColor = KcolorHex(@"#F3F6FA");
    [DTKTool YJ:kwt(3) andView:rzview];
    [backview addSubview:rzview];
    [rzview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(rwview.mas_right).offset(kwt(18));
        make.top.equalTo(dbview);
        make.width.offset(kwt(60));
        make.height.offset(kwt(56));
    }];
    rzview.addClickBlock(^{
        if(weakSelf.openRZBlock){
            weakSelf.openRZBlock(weakSelf.model);
        }
    });
    UIImageView * rzImg = kimageView(@"rizhi");
    [rzview addSubview:rzImg];
    [rzImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(kwt(8));
        make.height.width.offset(kwt(20));
    }];
    
    
    UILabel * rztemplab = [DTKTool labelWithText:@"日志" andFont:kFont(13) andTextColor:KcolorHex(@"#7D7D7D")];
    [rzview addSubview:rztemplab];
    [rztemplab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(kwt(36));
    }];
    
    
}
- (void)setModel:(appPondManageListModel *)model{
    _model = model;
    if(model.alarmDegree == -1){
        self.alarmLab.text = @"正常";
        self.alarmLab.textColor = KcolorHex(@"#0967FF");
        self.alarmLab.backgroundColor = KcolorHex(@"#E0ECFF");
        self.tkImg.image = [UIImage imageNamed:@"single"];
    } else  if(model.alarmDegree == 1){
        self.alarmLab.text = @"异常";
        self.alarmLab.textColor = KcolorHex(@"#F61A1A");
        self.alarmLab.backgroundColor = KcolorHex(@"#FFE6E6");
        self.tkImg.image = [UIImage imageNamed:@"abnormal_mouth"];

    } else {
        self.alarmLab.text = @"紧急";
        self.alarmLab.textColor = KcolorHex(@"#F61A1A");
        self.alarmLab.backgroundColor = KcolorHex(@"#FFE6E6");
        self.tkImg.image = [UIImage imageNamed:@"abnormal_mouth"];

    }
    self.nameLab.text = model.name;
}

- (void)openTkClick{
    if(self.openTKBlock){
        self.openTKBlock(self.model);
    }
}

@end
